package com.lanou.musicproject.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.lanou.musicproject.R;
import com.lanou.musicproject.activity.MainActivity;
import com.lanou.musicproject.activity.MusicPlayActivity;
import com.lanou.musicproject.bean.MyMusicList;
import com.lanou.musicproject.bean.NewSong;
import com.lanou.musicproject.bean.RecommHotSong;
import com.lanou.musicproject.suspendservice.FxService;
import com.squareup.picasso.Picasso;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by 王世美 on 15/10/27.
 * 推荐页-最新歌曲
 */
public class RecommNewSongAdapter extends BaseAdapter {
    private List<NewSong.PlazeAlbumListEntity.RMEntity.AlbumListEntity.ListEntity> data;
    private Context context;

    public RecommNewSongAdapter(Context c, List<NewSong.PlazeAlbumListEntity.
            RMEntity.AlbumListEntity.ListEntity> data) {
        this.data = data;
        context = c;
    }

    @Override
    public int getCount() {
        if (data != null && data.size() > 0)
            return data.size();
        else
            return 0;
    }

    @Override
    public NewSong.PlazeAlbumListEntity.RMEntity.AlbumListEntity
            .ListEntity getItem(int position) {
        if (data != null && data.size() > 0)
            return data.get(position);
        else
            return null;
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(final int position, View convertView,
                        ViewGroup parent) {
        ViewHolder holder = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.
                    layout.recomm_gridview_newsong_item, null);
            holder = new ViewHolder();
            holder.newSongIV = (ImageView) convertView.findViewById(R.id.newSongIV);
            holder.titleTV = (TextView) convertView.findViewById(R.id.titleTV);
            holder.authorTV = (TextView) convertView.findViewById(R.id.authorTV);

            convertView.setTag(holder);
        } else {
            holder= (ViewHolder) convertView.getTag();
        }
            NewSong.PlazeAlbumListEntity.RMEntity.AlbumListEntity.ListEntity list = getItem(position);
            if (list != null) {
                Picasso.with(context).load(list.getPic_radio()).into(holder.newSongIV);
                holder.titleTV.setText(list.getTitle());
                holder.authorTV.setText(list.getAuthor());

            }

        return convertView;
    }
    private class ViewHolder {
        public ImageView newSongIV;
        public TextView titleTV;
        public TextView authorTV;


    }
}

